package org.example.ui.controller;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.example.application.UserAccountService;
import org.example.domain.model.entity.user.req.UserRegisterReq;
import org.example.domain.model.entity.user.req.UserUpdateReq;
import org.example.domain.model.entity.user.resp.UserMessageResp;
import org.example.domain.system.model.UserAccount;
import org.example.web.result.ResultInfo;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api/domain/v1/user")
@Tag(name = "用户管理模块", description = "用户管理")
@RequiredArgsConstructor
public class UserAccountController {
    private final UserAccountService userAccountService;


    @GetMapping("/getUserByUserName")
    @Operation(summary = "根据用户名查询用户")
    public ResultInfo<UserMessageResp> getUserByUserName(@RequestParam String userName) {
        UserMessageResp userMessageResp = userAccountService.getUserByUserName(userName);
        return ResultInfo.success(userMessageResp);
    }

    @GetMapping("/getUserAccountByUserName")
    @Operation(summary = "根据用户名查询用户全部信息")
    public ResultInfo<UserAccount> getUserAccountByUserName(@RequestParam String userName) {
        UserAccount userAccount = userAccountService.getUserAccountByUserName(userName);
        return ResultInfo.success(userAccount);
    }


    @GetMapping("/getUserAccountToken")
    @Operation(summary = "根据Token查询用户全部信息")
    public ResultInfo<UserAccount> getUserAccountByToken() {
        UserAccount userAccount = userAccountService.getUserAccountByToken();
        return ResultInfo.success(userAccount);
    }

    @PostMapping("/registerUser")
    @Operation(summary = "注册用户")
    public ResultInfo registerUser(@Valid @RequestBody UserRegisterReq userRegisterReq) {
        return userAccountService.registerUser(userRegisterReq);

    }

    @PostMapping("/updateUser")
    @Operation(summary = "更新用户")
    public ResultInfo updateUser(@Valid @RequestBody UserUpdateReq userUpdateReq) {
        return userAccountService.updateUser(userUpdateReq);
    }


}
